package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 动态条件查询
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 菜品数量更新
     * @param shoppingCart1
     */
    @Update("update shopping_cart set number=#{number} where id =#{id}")
    void updateNumber(ShoppingCart shoppingCart1);

    /**
     * 添加菜品
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) VALUES " +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 清空购物车
     * @param currentId
     */
    @Delete("DELETE from shopping_cart where user_id =#{currentId}")
    void cleanByUserId(Long currentId);

    /**
     * 根据id删除购物车的一条数据
     * @param id
     */
    @Delete("DELETE from shopping_cart where id =#{id}")
    void DeleteById(Long id);

    /**
     * 根据用户userId删除购物车
     * @param userId
     */
    @Delete("DELETE from shopping_cart where user_id =#{userId}")
    void DeleteByUserId(Long userId);

    /**
     * 批量增加
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
